package com.hym.travel.service.serviceImpl;

import com.hym.travel.dao.UserDao;
import com.hym.travel.entity.User;
import com.hym.travel.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;
    @Override
    public User findUserByUsername(User user) {
        User userDB = new User();
        userDB = userDao.findUserByUsername(user);
        if(userDB != null){
            if(!user.getPassword().equals(userDB.getPassword())){
                throw new RuntimeException("密码输入错误");
            }
        }else{
            throw new RuntimeException("用户名输入错误");
        }
        return userDB;
    }

    @Override
    public void save(User user) {
        if(userDao.findUserByUsername(user) != null){
            throw new RuntimeException("该账号已经存在。");
        }
        userDao.save(user);
    }
}
